Error in value of default parameter [Bug in Visual C++ 2008?]

Posted by HellBoy on Stack Overflow See other posts from Stack Overflow or by HellBoy
Published on 2012-11-21T10:08:55Z Indexed on 2012/11/21 11:02 UTC
Read the original article Hit count: 142

Filed under:
|
|
|
|

I am facing following issue while trying to use template in my code

I have some C++ code which i call from C functions.

Problem is I am getting different values in the following code for statement 1 and 2.

Type id : unsigned int
statement 1 : 4
statement 2 : 1

C++ Code :

template <typename T>
void func(T* value, unsigned int len = sizeof(T)) {
     cout << "Type id : " << typeid(T).name() << endl;
     cout << "statement 1 " << sizeof(T) << endl;
     cout << "statement 2 " << len << endl;
}

template <typename T>
void func1(T data) {
    T val = data;
    func(&val);
}

C Code :

void test(void *ptr, unsigned int len) {
   switch(len) {
      case 1:
          func1(*(static_cast<uint32_t *>(ptr))
          break;
   }
}

This happens only on windows. On Linux it works fine.

© Stack Overflow or respective owner

Related posts about c++

Related posts about linux